package ${package}.service.impl;

/**
 * ${description}
 *
 * @author ${author}
 * @version ${createDate}
 */
public class ${beanName}ServiceImpl implements ${beanName}Service {

	private ${beanName}Dao ${uncapitalizeBeanName}Dao;
	private ICommonDao commonDao;
	
	public boolean delete(Long id) {
		
		Long []ids = new Long[1];
		ids[0] = id;
		commonDao.delete(ids, ${beanName}.class);
		return true;
	}

	@SuppressWarnings("unchecked")
	public List<${beanName}> get${beanName}(${beanName}Form ${uncapitalizeBeanName}) {
		
		StringBuffer hql = new StringBuffer("FROM ${beanName} f WHERE 1=1 ");
		if (${uncapitalizeBeanName} != null) {
			// TODO 查询条件
		}
		return commonDao.list(hql.toString(), ${uncapitalizeBeanName}.getSearchModel().getPage());
	}
	
	@SuppressWarnings("unchecked")
	public List<${beanName}> get${beanName}() {
		
		StringBuffer hql = new StringBuffer("FROM ${beanName} f WHERE 1=1 ");
		return commonDao.list(hql.toString());
	}

	public boolean save(${beanName}Form ${uncapitalizeBeanName}) throws IllegalAccessException, InvocationTargetException {
		
		${beanName} save${beanName} = new ${beanName}();
		BeanUtils.copyProperties(save${beanName}, ${uncapitalizeBeanName});
		
		commonDao.save(save${beanName}, ${beanName}.class);
		commonDao.flush();
		return true;
	}

	public boolean update(${beanName}Form ${uncapitalizeBeanName}) throws IllegalAccessException, InvocationTargetException {
		
		${beanName} update${beanName} = new ${beanName}();
		BeanUtils.copyProperties(update${beanName}, ${uncapitalizeBeanName});
		
		commonDao.update(update${beanName}, ${beanName}.class);
		commonDao.flush();
		return true;
	}
	
	public ${beanName} get(String id) {
		
		if (null == id || "".equals(id)) {
			return null;
		}
		return (${beanName}) commonDao.list("FROM ${beanName} f WHERE f.id=" + id).get(0);
	}

	public ${beanName}Dao get${beanName}Dao() {
		return ${uncapitalizeBeanName}Dao;
	}

	public void set${beanName}Dao(${beanName}Dao ${uncapitalizeBeanName}Dao) {
		this.${uncapitalizeBeanName}Dao = ${uncapitalizeBeanName}Dao;
	}

	public ICommonDao getCommonDao() {
		return commonDao;
	}

	public void setCommonDao(ICommonDao commonDao) {
		this.commonDao = commonDao;
	}

}
